#include"c3pom/log.h"
#include"c3pom/application.h"
#include<time.h>
using namespace std;
using namespace c3pom;
static Log* instance=NULL;

Log* Log::getInstance()
{
	if(instance==NULL)
		instance=new Log();
	return instance;
}
string Log::getTimeofDay()
{
	time_t timet=time(NULL);
	string time=string(asctime(localtime(&timet)));
	if(time.find("\n")==time.length()-1)
	{
		time=string(time,0,time.length()-1);
	}
	time=string("[")+time+string("]");
	return time;
}
void Log::warn(string message)
{
	f<<getTimeofDay()<<swarn<<message<<endl;
}

void Log::error(string message)
{
	f<<getTimeofDay()<<serror<<message<<endl;
}

void Log::info(string message)
{
	f<<getTimeofDay()<<sinfo<<message<<endl;
}

string Log::name()
{
	return "log";
}

string Log::desc()
{
	return "c3pom日志服务";
}

void Log::run()
{
}

Log::Log()
{
	sinfo="(INFO)";
	serror="(ERRO)";
	swarn="(WARN)";
	string filename=Application::getInstance()->envar["LOG_FILE"];
	f.open(filename.c_str(),ios::out|ios::app);
}
